package LearnAlgorithm.c_递归and查找排序;

public class i旋转后的数组求最小值 {
	public static void main(String[] args) {
		int[] arr2 = new int[] {6,7,8,9,10,1,2,3,4,5};
		System.out.println(srarchMin(arr2));
		int[] arr3 = {3,3,3,3,3,0,1,2,3};
		System.out.println(srarchMin(arr3));
	}
	
	private static int srarchMin(int[] arr) {
		int begin = 0;
		int end = arr.length-1;
		int mid = 0;
		int min = 0;
		if (arr[begin] < arr[end]) {
			return arr[begin];
		}
		while (begin+1 < end) {
			mid = begin + ((end - begin) >>> 1);
			
			
			
			if (arr[mid] == arr[begin]) {//左边索引begin和索引mid上的值大小一样，那么就用扫描法呗老老实实找。
				min = arr[begin];
				for (int i = begin; i <= end; i++) {
					if (min >= arr[i]) {
						min = arr[i];
					}
				}
				return min;
			}
			
			
			
			if (arr[mid] >= arr[begin]) {
				begin = mid;
			} else {
				end = mid;
			}
		}
		return arr[end];
	}
}
